package com.springboot.java.design.iterator;

import java.util.List;

/**
 * @Author: TongRui乀
 * @Date: 2019-12-16 17:20
 * @description：  具体聚合类
 */
public class ProductCollection extends AbstractObjectCollection{

    public ProductCollection(List<Object> lists){
        super(lists);
    }

    @Override
    public AbstractIterator iterator() {
        return new ProductIterator();
    }

    private class ProductIterator implements AbstractIterator{

        /**
         *  游标
         */
        private int cursor = 0;

        @Override
        public boolean hasNext() {
            return this.cursor <= (list.size() - 1);
        }

        @Override
        public Object next() {
            Object o = list.get(cursor);
            this.cursor += 1;
            return o;
        }
    }
}
